package com.hxj.ecokey.controller;

import com.hxj.ecokey.entity.Product; // 修改为Product
import com.hxj.ecokey.service.ProductService;
import com.hxj.ecokey.service.UserPointsService;
import com.hxj.ecokey.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/pointmall")
public class PointMallController {
    @Autowired
    private ProductService productService;

    @Autowired
    private UserPointsService userPointsService;

    @GetMapping("/points")
    public Result getUserPoints(@RequestParam Integer userId) {
        int points = userPointsService.getUserPoints(userId);
        return Result.success("获取积分成功", points);
    }

    @GetMapping("/products") // 添加GetMapping注解
    public Result getAllProducts() { // 移除泛型，与Result类匹配
        List<Product> products = productService.getAllProducts(); // 修改为Product
        return Result.success("获取商品列表成功", products);
    }
}